//package com.boot2.core.conf;
//
//import org.springframework.aop.aspectj.AspectJExpressionPointcutAdvisor;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.transaction.PlatformTransactionManager;
//import org.springframework.transaction.TransactionDefinition;
//import org.springframework.transaction.interceptor.*;
//
//import java.util.Collections;
//import java.util.HashMap;
//import java.util.Map;
//
///**
// * @author zhangweilin
// * @ClassName: TxConfig
// * @description: 全局声明式事务配置
// * @date 2017年12月22日 下午5:47:56
// */
//@Configuration
//public class TxConfig {
//    @Bean("txSource")
//    public TransactionAttributeSource transactionAttributeSource() {
//        NameMatchTransactionAttributeSource source = new NameMatchTransactionAttributeSource();
//        RuleBasedTransactionAttribute readOnlyTx = new RuleBasedTransactionAttribute();
//        readOnlyTx.setReadOnly(true);
//        readOnlyTx.setPropagationBehavior(TransactionDefinition.PROPAGATION_NOT_SUPPORTED);
//        RuleBasedTransactionAttribute requiredTx = new RuleBasedTransactionAttribute(TransactionDefinition.PROPAGATION_REQUIRED,
//                Collections.singletonList(new RollbackRuleAttribute(Exception.class)));
//        int isolationLevel = requiredTx.getIsolationLevel();
//        // requiredTx.setTimeout(90);
//        Map<String, TransactionAttribute> txMap = new HashMap<>();
//        txMap.put("init*", requiredTx);
//        txMap.put("add*", requiredTx);
//        txMap.put("save*", requiredTx);
//        txMap.put("insert*", requiredTx);
//        txMap.put("create*", requiredTx);
//        txMap.put("persist*", requiredTx);
//        txMap.put("update*", requiredTx);
//        txMap.put("modify*", requiredTx);
//        txMap.put("merge*", requiredTx);
//        txMap.put("bind*", requiredTx);
//        txMap.put("delete*", requiredTx);
//        txMap.put("del*", requiredTx);
//        txMap.put("drop*", requiredTx);
//        txMap.put("remove*", requiredTx);
//        txMap.put("reset*", requiredTx);
//        txMap.put("cancel*", requiredTx);
//        txMap.put("login*", requiredTx);
//        txMap.put("*", readOnlyTx);
//        source.setNameMap(txMap);
//
//        return source;
//    }
//
//
//    @Bean
//    public AspectJExpressionPointcutAdvisor pointcutAdvisor(TransactionInterceptor txInterceptor) {
//        AspectJExpressionPointcutAdvisor pointcutAdvisor = new AspectJExpressionPointcutAdvisor();
//        pointcutAdvisor.setAdvice(txInterceptor);
////		pointcutAdvisor.setExpression("execution (* com.boot2..service..*.*(..))");
//        pointcutAdvisor.setExpression("execution (* com..service..*.*(..)) || execution (* com..dao..*.*(..))");
//        return pointcutAdvisor;
//    }
//
//    @Bean("txInterceptor")
//    TransactionInterceptor getTransactionInterceptor(PlatformTransactionManager tx) {
//        return new TransactionInterceptor(tx, transactionAttributeSource());
//    }
//
//}